package object.library.operation;

import object.library.Book;
import object.library.BookList;

import java.util.Scanner;

public class FindOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("查找操作");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入查找的书名：");
        String name = scanner.next();
        int flag = 0;
        for(int i = 0; i < bookList.getSize(); i++){
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("book["+i+"]:"+book);
                flag = 1;
            }
        }
        if(flag == 0){
            System.out.println("没有这本书，重新输入");
            return;
        }
        System.out.println("查找结束");
    }
}
